<script>
import Vue from 'vue'
import md5Libs from "uview-ui/libs/function/md5";
export default {
	onLaunch: async function() {
		uni.getSystemInfo({
			success: function(e) {
				// #ifndef MP
				Vue.prototype.StatusBar = e.statusBarHeight;
				if (e.platform == 'android') {
					Vue.prototype.CustomBar = e.statusBarHeight + 50;
				} else {
					Vue.prototype.CustomBar = e.statusBarHeight + 45;
				};
				// #endif
		
				// #ifdef MP-WEIXIN
				Vue.prototype.StatusBar = e.statusBarHeight;
				let custom = wx.getMenuButtonBoundingClientRect();
				Vue.prototype.Custom = custom;
				Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
				// #endif		
		
				// #ifdef MP-ALIPAY
				Vue.prototype.StatusBar = e.statusBarHeight;
				Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
				// #endif
			}
		})
		console.log('uview 版本', this.$u.config.v);
		// #ifdef H5
		if(window.location.hash != ''){
			 let search = window.location.search.substring(1);
			    try{
			        if(search.indexOf('hashpath') != -1){
			            let sea = JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
			            if(sea.hashpath && sea.code && sea.state){
			                window.location.href = window.location.origin + window.location.pathname+'#'+sea.hashpath+'?code='+sea.code+'&state='+sea.state
			            }
			        }
			    }catch(e){
			        //TODO handle the exception
			    }
		}
		// #endif

		//加载配置
		let res = await this.$api.getConfig();
		if (!res.code) {
			return;
		}
		//主题做缓存
		let theme_key = md5Libs.md5(JSON.stringify(res.data.theme));
		if(!this.vuex_theme.key || this.vuex_theme.key != theme_key){
			this.$u.vuex('vuex_theme', {key:theme_key,value:res.data.theme});
		}
		
		this.$u.vuex('vuex_config', res.data);
		
		// #ifdef APP-PLUS
		let tabbar = this.$u.deepClone(this.vuex_config.tabbar);
		if (!tabbar) {
			this.$util.setTabbar(this.vuex_tabbar);
			return;
		}
		let num = 0;
		for (let i in tabbar.list) {
			try {
				let imagepath = await this.$util.getCachedImage(tabbar.list[i].image);
				let selectedImage = await this.$util.getCachedImage(tabbar.list[i].selectedImage);
				tabbar.list[i].image = imagepath;
				tabbar.list[i].selectedImage = selectedImage;
				num = i;
			} catch (e) {
				console.log(e);
			}
		}
		//更新tabbar配置
		this.$u.vuex('vuex_config.tabbar.list', tabbar.list);
		return ;
		
		//全部下载成功使用服务器的导航，否则启用本地备用导航
		if (parseInt(num) + 1 == tabbar.list.length) {
			this.$util.setTabbar(tabbar);
		} else {
			this.$util.setTabbar(this.vuex_tabbar);
		}
		// #endif
	},
	onShow: function() {
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
	}
};
</script>

<style lang="scss">
// @import 'uview-ui/index.scss';
@import "colorui/style.css";
@import "colorui/main.css";
@import "colorui/icon.css";
@import 'static/css/common.scss';
@import 'static/css/zcm-main.css';
@import 'static/css/ali-icon.css';
page{
	background-color: #F5F5F5;
}
/*每个页面公共css */
.u-bg-white {
	background-color: #ffffff;
}
.u-text-weight {
	font-weight: bold;
}

.u-line-height {
	line-height: 50rpx;
}
//数据为空的样式
.fa-empty {
	padding-top: 45%;
}

.share-btn {
	padding: 0;
	margin: 0;
	border: 0;
	background-color: transparent;
	line-height: inherit;
	border-radius: 0;
	font-size: inherit;
	color: #999;
}
.share-btn::after {
	border: none;
}

// #ifdef MP-BAIDU
.u-radio__icon-wrap,.u-checkbox__icon-wrap{
	line-height: 0;
}
// #endif
.lgog-img{
	margin-top: 450rpx;
	width: 42px;
	height: 58.39px;
}
.jqqd{
	font-size: 12px;
	color: #767879;
}
.text-centers{
	text-align: center;
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%,-50%);
}
.text-centers image{
	width: 154rpx;
	height: 215rpx;
}
.text-centers {
	.jqqds{
	font-size: 32rpx;
	font-family: PingFang SC, PingFang SC;
	font-weight: 500;
	color: #000000;
	line-height: 38rpx;
	margin-top: 48rpx;
	margin-bottom: 4rpx;
   }
   .open-descs{
   	font-size: 24rpx;
   	font-family: PingFang SC, PingFang SC;
   	font-weight: 400;
   	color: #767879;
   	line-height: 28rpx;
   }
}
</style>
